﻿using System;
using System.Web.Mvc;
using System.Web.Http;
using Jw.Core;
using Jw.Models;
using Jw.Web.Areas.Pacm.Common;
using CommonUtilities.DataBase;
using System.Data;
using Jw.Utils;
using System.Collections.Generic;
using Jw.Web.App_Start;

namespace Jw.Web.Areas.Pacm.Controllers
{
    public class ScsjController : BaseController
    {
        // 生产日报
        // GET: /Pacm/Scsj/
        public ActionResult Index()
        {
            var codeService = new sys_codeService();
            var model = new
            {
                idField = "", //主键
                urls = new
                {
                    query = "/api/Pacm/Scsj/Get1/"
                },
                resx = PacmHelper.GetIndexResx("生产日报"),
                dataSource = new
                {
                    gqzdItems = new p_GqzdService().GetGqzdList(), //工区字典
                    yearItems = codeService.GetYearItems(),
                    monthItems = codeService.GetMonthItems()
                },
                form = new
                {
                    Scsj_Ch = "",
                    Scsj_Rq = DateTime.Now.Date.AddDays(-1).ToString("yyyy-MM-dd"),
                    Gqzd_Gqbh = ""
                }

            };
            return View(model);
        }
        /// <summary>
        /// 日用电量
        /// </summary>
        /// <returns></returns>
        public ActionResult RydlList()
        {
            var codeService = new sys_codeService();
            var model = new
            {
                idField = "", //主键
                urls = new
                {
                    query = "/api/Pacm/Scsj/GetRydl/"
                },
                resx = PacmHelper.GetIndexResx("日用电量统计"),
                dataSource = new
                {
                    dbzdItems = new n_DbzdService().GetDbzdList2(), //电表字典
                    yearItems = codeService.GetYearItems(),
                    monthItems = codeService.GetMonthItems()
                },
                form = new
                {
                    Dbzd_Dbmc = "", //电表名称
                    CreateDate = "",//采集时间
                    Rydl_Syrq = DateTime.Now.Date.ToString("yyyy-MM-dd"),
                }

            };
            return View(model);
        }
        /// <summary>
        /// 月用电量
        /// </summary>
        /// <returns></returns>
        public ActionResult YydlList()
        {
            var codeService = new sys_codeService();
            var model = new
            {
                idField = "", //主键
                urls = new
                {
                    query = "/api/Pacm/Scsj/GetYydl/"
                },
                resx = PacmHelper.GetIndexResx("月用电量统计"),
                dataSource = new
                {
                    dbzdItems = new n_DbzdService().GetDbzdList(), //工区字典
                    yearItems = codeService.GetYearItems(),
                    monthItems = codeService.GetMonthItems()
                },
                form = new
                {
                    Yydl_Dbbh = "", //电表编号
                    Yydl_Year = DateTime.Now.Date.ToString("yyyy"),
                    Yydl_Month = DateTime.Now.Date.ToString("MM")
                }

            };
            return View(model);
        }
        /// <summary>
        /// 电表数据采集数据
        /// </summary>
        /// <returns></returns>
        public ActionResult CounterList()
        {
            var codeService = new sys_codeService();
            var model = new
            {
                idField = "", //主键
                urls = new
                {
                    query = "/api/Pacm/Scsj/GetCounter/"
                },
                resx = PacmHelper.GetIndexResx("电量采集数据"),
                dataSource = new
                {
                    dbzdItems = new n_DbzdService().GetDbzdList2(), //电表字典
                    yearItems = codeService.GetYearItems(),
                    monthItems = codeService.GetMonthItems(),
                    dayItesm = codeService.GetDayItems()
                },
                form = new
                {
                    Counter名称 = "", //电表编号
                    年度 = DateTime.Now.Date.ToString("yyyy"),
                    月份 = DateTime.Now.Date.ToString("MM"),
                    日 = DateTime.Now.ToString("dd")
                }

            };
            return View(model);
        }
        /// <summary>
        /// 电表数据实时负荷
        /// </summary>
        /// <returns></returns>
        public ActionResult AiList()
        {
            var codeService = new sys_codeService();
            var model = new
            {
                idField = "", //主键
                urls = new
                {
                    query = "/api/Pacm/Scsj/GetAi/"
                },
                resx = PacmHelper.GetIndexResx("电表实时负荷"),
                dataSource = new
                {
                    dbzdItems = new n_AIService().GetAiDbzdList(), //Ai电表字典
                    yearItems = codeService.GetYearItems(),
                    monthItems = codeService.GetMonthItems(),
                    dayItesm = codeService.GetDayItems()
                },
                form = new
                {
                    AI名称 = "", //电表名称
                    年 = DateTime.Now.Date.ToString("yyyy"),
                    月 = DateTime.Now.Date.Month.ToString(),
                    日 = DateTime.Now.Date.ToString("dd")
                }

            };
            return View(model);
        }
        /// <summary>
        /// 日用水量查询
        /// </summary>
        /// <returns></returns>
        public ActionResult RyslList()
        {
            var codeService = new sys_codeService();
            var model = new
            {
                idField = "", //主键
                urls = new
                {
                    query = "/api/Pacm/Scsj/GetRysl/"
                },
                resx = PacmHelper.GetIndexResx("日用水量统计"),
                dataSource = new
                {
                    sbzdItems = new n_SbzdService().GetSbzdList(), //水表字典
                    yearItems = codeService.GetYearItems(),
                    monthItems = codeService.GetMonthItems()
                },
                form = new
                {
                    Sbzd_Sbmc = "", //水表名称
                    CreateDate = "",//采集时间
                    Rysl_Rq = DateTime.Now.Date.ToString("yyyy-MM-dd"),
                }

            };
            return View(model);
        }
        /// <summary>
        /// 月用水量查询
        /// </summary>
        /// <returns></returns>
        public ActionResult YyslList()
        {
            var codeService = new sys_codeService();
            var model = new
            {
                idField = "", //主键
                urls = new
                {
                    query = "/api/Pacm/Scsj/GetYysl/"
                },
                resx = PacmHelper.GetIndexResx("月用水量统计"),
                dataSource = new
                {
                    sbzdItems = new n_SbzdService().GetSbzdList(), //水表字典
                    yearItems = codeService.GetYearItems(),
                    monthItems = codeService.GetMonthItems()
                },
                form = new
                {
                    Sbzd_Bmmc = "", //水表名称
                    CreateDate = "",//采集时间
                    Yysl_Year = DateTime.Now.Date.ToString("yyyy"),
                    Yysl_Month = DateTime.Now.Date.ToString("MM")
                }

            };
            return View(model);
        }
        /// <summary>
        /// 实时负荷曲线图
        /// </summary>
        /// <returns></returns>
        public ActionResult ChartAiList()
        {
            var codeService = new sys_codeService();
            var model = new
            {
                idField = "", //主键
                urls = new
                {
                    query = "/api/Pacm/Scsj/GetChartAiZoomLine"
                },
                resx = PacmHelper.GetIndexResx("负荷曲线图"),
                dataSource = new
                {
                    dbzdItems = new n_AIService().GetAiDbzdList(), //在n_Ai表里获取电表字典
                },
                form = new
                {
                    AI名称 = "", //电表名称
                    日期 = DateTime.Now.ToString("yyyy-MM-dd")
                }

            };
            return View(model);
        }
        /// <summary>
        /// 槽控实时电流电压
        /// </summary>
        /// <returns></returns>
        public ActionResult ChartSlotUIList()
        {
            var codeService = new sys_codeService();
            var model = new
            {
                idField = "", //主键
                urls = new
                {
                    query = "/api/Pacm/Scsj/GetChartSlotUIZoomLine"
                },
                resx = PacmHelper.GetIndexResx("电压电流曲线图"),
                dataSource = new
                {
                },
                form = new
                {
                    槽号 = "1001", //槽号名称
                    日期 = DateTime.Now.ToString("yyyy-MM-dd") //日期
                }

            };
            return View(model);
        }
    }
    public class ScsjApiController : ApiController
    {
        public string Func(WhereData wheredata)
        {
            return wheredata.Value.ToString();
        }


        /// <summary>槽控数据
        /// 槽控数据
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public dynamic Get1(RequestWrapper query)
        {
            Func<WhereData, string> test = Func;

            query.LoadSettingXmlString(@"
            <settings defaultOrderBy='Scsj_Rq'>
                <select>
                  C.Gqzd_Gqbh,C.Gqzd_Gqmc,A.*
                </select>
                <from>
                    p_Scsj A  
                    left outer join   p_Chzd B on A.Scsj_Ch = B.Chzd_Ch
                    left outer join   p_Gqzd C on C.Gqzd_Gqbh = B.Chzd_Gqbh
                </from>
                <where defaultForAll='true' defaultCp='equal' defaultIgnoreEmpty='true' >
                    <field name='Scsj_Rq'             cp='daterange'     ></field>
                    <field name='Gqzd_Gqbh'           cp='equal'     ></field>
                </where>
            </settings>
            ");
            var pQuery = query.ToParamQuery();
            var list = new p_ScsjService().GetDynamicListWithPaging(pQuery);

            #region 合计
            var list2 = new p_ScsjService().GetDynamicList(pQuery);
            decimal d_Scsj_Cy_Sddy = 0; //设定电压
            int i_Scsj_Cl = 0; //槽龄
            decimal d_Scsj_Cy_Gzdy = 0; //工作电压
            decimal d_Scsj_Cy_Pjdy = 0; //平均电压

            decimal d_Scsj_Jl_Zjll = 0; //总加料量
            decimal d_Scsj_Clh_Fe = 0; //Fe含量
            decimal d_Scsj_Clh_Si = 0; //Si含量
            decimal d_Scsj_Clh_Yhlnd = 0; //氧化铝浓度
            decimal d_Scsj_Jl_Zfyl = 0;//总氟盐量

            decimal d_Scsj_Clh_Fzb = 0; //分子比
            decimal d_Scsj_Clh_Cll = 0; //出铝量
            decimal d_Scsj_Clh_Zsp = 0; //质水平
            decimal d_Scsj_Clh_Lsp = 0; //铝水平
            decimal d_Scsj_Clh_Cwd = 0; //槽温度
            for (int i = 0; i < list2.Count; i++)
            {
                //设定电压
                object s = list2[i].Scsj_Cy_Sddy;
                if (s != null) d_Scsj_Cy_Sddy += Convert.ToDecimal(s);
                //槽龄
                s = list2[i].Scsj_Cl;
                if (s != null) i_Scsj_Cl += Convert.ToInt16(s);
                //工作电压
                s = list2[i].Scsj_Cy_Gzdy;
                if (s != null) d_Scsj_Cy_Gzdy += Convert.ToDecimal(s);
                //平均电压
                s = list2[i].Scsj_Cy_Pjdy;
                if (s != null) d_Scsj_Cy_Pjdy += Convert.ToDecimal(s);
                //总加料量
                s = list2[i].Scsj_Jl_Zjll;
                if (s != null) d_Scsj_Jl_Zjll += Convert.ToDecimal(s);
                //Fe
                s = list2[i].Scsj_Clh_Fe;
                if (s != null) d_Scsj_Clh_Fe += Convert.ToDecimal(s);
                //Si 
                s = list2[i].Scsj_Clh_Si;
                if (s != null) d_Scsj_Clh_Si += Convert.ToDecimal(s);
                //氧化铝浓度
                s = list2[i].Scsj_Clh_Yhlnd;
                if (s != null) d_Scsj_Clh_Yhlnd += Convert.ToDecimal(s);
                //总氟盐量
                s = list2[i].Scsj_Jl_Zfyl;
                if (s != null) d_Scsj_Jl_Zfyl += Convert.ToDecimal(s);
                //分子比
                s = list2[i].Scsj_Clh_Fzb;
                if (s != null) d_Scsj_Clh_Fzb += Convert.ToDecimal(s);
                //出铝量
                s = list2[i].Scsj_Clh_Cll;
                if (s != null) d_Scsj_Clh_Cll += Convert.ToDecimal(s);
                //质水平
                s = list2[i].Scsj_Clh_Zsp;
                if (s != null) d_Scsj_Clh_Zsp += Convert.ToDecimal(s);
                //铝水平
                s = list2[i].Scsj_Clh_Lsp;
                if (s != null) d_Scsj_Clh_Lsp += Convert.ToDecimal(s);
                //槽温度
                s = list2[i].Scsj_Clh_Cwd;
                if (s != null) d_Scsj_Clh_Cwd += Convert.ToDecimal(s);

            }
            var hj = new List<dynamic>();
            hj.Add(new
            {
                Scsj_Ch = "合计",
                Scsj_Cy_Sddy = d_Scsj_Cy_Sddy,
                Scsj_Cl = i_Scsj_Cl,
                Scsj_Cy_Gzdy = d_Scsj_Cy_Gzdy,
                Scsj_Cy_Pjdy = d_Scsj_Cy_Pjdy,
                Scsj_Jl_Zjll = d_Scsj_Jl_Zjll,
                Scsj_Clh_Fe = d_Scsj_Clh_Fe,
                Scsj_Clh_Si = d_Scsj_Clh_Si,
                Scsj_Clh_Yhlnd = d_Scsj_Clh_Yhlnd,
                Scsj_Jl_Zfyl = d_Scsj_Jl_Zfyl,
                Scsj_Clh_Fzb = d_Scsj_Clh_Fzb,
                Scsj_Clh_Cll = d_Scsj_Clh_Cll,
                Scsj_Clh_Zsp = d_Scsj_Clh_Zsp,
                Scsj_Clh_Lsp = d_Scsj_Clh_Lsp,
                Scsj_Clh_Cwd = d_Scsj_Clh_Cwd
            });
            //ff.Add(new { Scsj_Ch = "合计", Scsj_Cy_Pjdy = 10 });
            list.footer = hj;// JsonConvert.SerializeObject(ff);
            #endregion

            return list;

        }

        /// <summary>
        /// 日用电量查询
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public dynamic GetRydl(RequestWrapper query)
        {
            //电表消耗日用量
            query.LoadSettingXmlString(@"
            <settings defaultOrderBy='Rydl_Syrq'>
                <select>
                 *
                </select>
                <from>
                    n_Rydl A  
                    left outer join   n_Dbzd B on A.Rydl_Dbbh = B.Dbzd_Dbbh
                </from>
                <where defaultForAll='true' defaultCp='equal' defaultIgnoreEmpty='true' >
                    <field name='Rydl_Syrq'             cp='daterange'     ></field>
                    <field name='Rydl_Dbbh'           cp='equal'     ></field>
                    <field name='Dbzd_Dbmc'           cp='like'     ></field>
                </where>
            </settings>
            ");
            var pQuery = query.ToParamQuery();
            var list = new p_ScsjService().GetDynamicListWithPaging(pQuery);
            return list;
        }
        /// <summary>
        /// 采集数据
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public dynamic GetCounter(RequestWrapper query)
        {
            query.LoadSettingXmlString(@"
            <settings defaultOrderBy='[年度]'>
                <select>
                 [年度]+'-' + [月份]+'-' + [日] as Rq,n_Counter.*
                </select>
                <from>
                    n_Counter 
                </from>
                <where defaultForAll='true' defaultCp='equal' defaultIgnoreEmpty='true' >
                    <field name='[年度]'           cp='equal'     ></field>
                    <field name='[月份]'           cp='equal'     ></field>
                    <field name='Counter名称'           cp='like'     ></field>
                </where>
            </settings>
            ");
            var pQuery = query.ToParamQuery();
            var list = new p_ScsjService().GetDynamicListWithPaging(pQuery);
            return list;
        }

        /// <summary>
        /// 电表实时负荷
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public dynamic GetAI(RequestWrapper query)
        {
            query.LoadSettingXmlString(@"
            <settings defaultOrderBy='[年]'>
                <select>
                 [年]+'-' + [月]+'-' + [日] as Rq,n_AI.*
                </select>
                <from>
                    n_AI 
                </from>
                <where defaultForAll='true' defaultCp='equal' defaultIgnoreEmpty='true' >
                    <field name='[年]'           cp='equal'     ></field>
                    <field name='[月]'           cp='equal'     ></field>
                    <field name='AI名称'         cp='like'    ></field>
                </where>
            </settings>
            ");
            var pQuery = query.ToParamQuery();
            var list = new n_AIService().GetDynamicListWithPaging(pQuery);
            return list;
        }


        /// <summary>
        /// 月用电量
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public dynamic GetYydl(RequestWrapper query)
        {
            query.LoadSettingXmlString(@"
            <settings defaultOrderBy='Yydl_Year'>
                <select>
                 *
                </select>
                <from>
                    n_Yydl A  
                    left outer join   n_Dbzd B on A.Yydl_Dbbh = B.Dbzd_Dbbh
                </from>
                <where defaultForAll='true' defaultCp='equal' defaultIgnoreEmpty='true' >
                    <field name='Yydl_Year'             cp='equal'     ></field>
                    <field name='Yydl_Month'           cp='equal'     ></field>
                </where>
            </settings>
            ");
            var pQuery = query.ToParamQuery();
            var list = new p_ScsjService().GetDynamicListWithPaging(pQuery);
            return list;
        }

        /// <summary>
        /// 日用水量
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public dynamic GetRysl(RequestWrapper query)
        {
            //电表消耗日用量
            query.LoadSettingXmlString(@"
            <settings defaultOrderBy='Rysl_Rq'>
                <select>
                 *
                </select>
                <from>
                    n_Rysl A  
                    left outer join   n_Sbzd B on A.Rysl_Sbbh = B.Sbzd_Sbbh
                </from>
                <where defaultForAll='true' defaultCp='equal' defaultIgnoreEmpty='true' >
                    <field name='Rysl_Rq'             cp='daterange'     ></field>
                    <field name='Rysl_Sbbh'           cp='equal'     ></field>
                    <field name='Sbzd_Sbmc'           cp='like'     ></field>
                </where>
            </settings>
            ");
            var pQuery = query.ToParamQuery();
            var list = new n_RyslService().GetDynamicListWithPaging(pQuery);
            return list;
        }

        /// <summary>
        /// 月用水量
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public dynamic GetYysl(RequestWrapper query)
        {
            query.LoadSettingXmlString(@"
            <settings defaultOrderBy='Yysl_Year'>
                <select>
                 *
                </select>
                <from>
                    n_Yysl A  
                    left outer join   n_Sbzd B on A.Yysl_Sbbh = B.Sbzd_Sbbh
                </from>
                <where defaultForAll='true' defaultCp='equal' defaultIgnoreEmpty='true' >
                    <field name='Yysl_Year'             cp='equal'     ></field>
                    <field name='Yysl_Month'           cp='equal'     ></field>
                </where>
            </settings>
            ");
            var pQuery = query.ToParamQuery();
            var list = new n_YyslService().GetDynamicListWithPaging(pQuery);
            return list;
        }
        /// <summary>
        /// 电表负荷_图
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public string GetChartAiZoomLine(RequestWrapper query)
        {
            //取负荷数据
            //context.Server.UrlDecode();
            //sName = Server.UrlDecode(sName); //字符串解码（特殊字符）
            //if (string.IsNullOrEmpty(sRq)) sRq = DateTime.Now.ToString("yyyy-MM-dd");
            string sRq = ZConvert.To<string>(query["日期"], "");
            string sName = ZConvert.To<string>(query["AI名称"], "");
            string sCurrRq = DateTime.Now.ToString("yyyy-MM-dd");
            int iHour = 23;
            int iMin = 60;
            //判断是不是当前日期
            if (Convert.ToDateTime(sCurrRq) <= Convert.ToDateTime(sRq))
            {
                iHour = DateTime.Now.Hour;
                iMin = DateTime.Now.Minute;
            }
            string sReturn = "没有数据...";
            using (var db = Db.Context("Pacm")) //创建连接
            {
                string sConnect = db.Data.ConnectionString;
                SQLHelper dbhelper = new SQLHelper(sConnect);
                string sSql = string.Format(@"select top 1 * from n_AI where 年+'-'+ 月+'-' + 日 = '{0}' and Ai名称 like '{1}%'", sRq, sName);
                DataTable dt = dbhelper.GetDataTable(sSql, new System.Data.SqlClient.SqlParameter[0]);

                string sHead = "";
                string categories = "";
                string dataset = "";
                string caption = "";
                string subcaption = "";
                if (dt.Rows.Count > 0)
                {
                    double dMax = 0;
                    caption = dt.Rows[0]["AI名称"].ToString();
                    subcaption = "日期:" + sRq;

                    for (int i = 0; i <= iHour; i++)
                    {
                        for (int j = 0; j < 60; j += 5)
                        {
                            if (i == iHour && j > iMin) continue;
                            categories += string.Format("{0}_{1}|", i.ToString().PadLeft(2, '0'), j.ToString().PadLeft(2, '0'));
                            double dvalue = dt.Rows[0][string.Format("实时值{0}_{1}", i.ToString().PadLeft(2, '0'), j.ToString().PadLeft(2, '0'))] == DBNull.Value ? 0 : Math.Round(Convert.ToDouble(dt.Rows[0][string.Format("实时值{0}_{1}", i.ToString().PadLeft(2, '0'), j.ToString().PadLeft(2, '0'))]), 3);
                            // 0值不能显示
                            if (dvalue > dMax) dMax = dvalue;
                            dataset += dvalue == 0 ? "" : dvalue.ToString() + "|";

                        }
                    }
                    sHead = string.Format(@"<chart compactDataMode='1' dataSeparator='|' caption='{0}' subcaption='{1}' axis='linear' numberPrefix='' formatNumberScale='0' decimals='3' yAxisMaxValue ='{2}'
                                             bgColor='#ffecec, E9E9E9' divLineColor='CC3300' lineColor='91AF46' allowPinMode='0' enableIconMouseCursors='0' dynamicAxis='1' palette='3'>", caption, subcaption, dMax * 1.3);

                    //                    sHead = string.Format(@"<chart compactDataMode='1' dataSeparator='|' caption='{0}' subcaption='{1}' axis='linear' numberPrefix='' formatNumberScale='0' 
                    //                                             bgColor='#ffecec, E9E9E9' divLineColor='CC3300' lineColor='91AF46' allowPinMode='0' enableIconMouseCursors='0' dynamicAxis='1' palette='3'>", caption, subcaption);

                    sReturn = string.Format(@"{0}<categories>{1}</categories><dataset seriesName='负荷' anchorBgColor ='FF0080' color='FF0080'>{2}</dataset></chart>", sHead, categories, dataset);
                }
            }
            return sReturn;
        }
        /// <summary>
        /// 槽控电压电流_图
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public string GetChartSlotUIZoomLine(RequestWrapper query)
        {
            //第一种方法
            //var context = HttpContext.Current;
            //var request = context.Request;
            //string sCPH = request["S_CPH"];
            //第二种方法

            string sRq = ZConvert.To<string>(query["日期"], "");
            string sCh = ZConvert.To<string>(query["槽号"], "");
            //sName = Server.UrlDecode(sName); //字符串解码（特殊字符）
            if (string.IsNullOrEmpty(sRq)) sRq = DateTime.Now.ToString("yyyy-MM-dd");
            string sCurrRq = DateTime.Now.ToString("yyyy-MM-dd");
            int iHour = 23;
            int iMin = 60;
            //判断是不是当前日期
            if (Convert.ToDateTime(sCurrRq) <= Convert.ToDateTime(sRq))
            {
                iHour = DateTime.Now.Hour;
                iMin = DateTime.Now.Minute;
            }

            string sReturn = "没有数据...";
            using (var db = Db.Context("Pacm")) //创建连接
            {
                string sConnect = db.Data.ConnectionString;
                SQLHelper dbhelper = new SQLHelper(sConnect);
                //string sSql = string.Format(@"select * from p_瞬时U where 日期= '{0}' and 槽号 = '{1}'", sRq, sCh);
                //DataTable dt_电压 = dbhelper.GetDataTable(sSql, new System.Data.SqlClient.SqlParameter[0]);
                //sSql = string.Format(@"select * from p_瞬时I where 日期= '{0}' and 槽号 = '{1}'", sRq, sCh);
                //DataTable dt_电流 = dbhelper.GetDataTable(sSql, new System.Data.SqlClient.SqlParameter[0]);

                string sSql = string.Format(@"select 时间,电流,电压,CONVERT(varchar(12) , 时间, 108 ) as sTime  from p_RawDatas where convert(varchar(10),时间,120) ='{0}' and 槽号 ='{1}' order by 时间 asc", sRq, sCh);
                DataTable dtDatas = dbhelper.GetDataTable(sSql, new System.Data.SqlClient.SqlParameter[0]);
                string categories = "";
                string Series电压 = "";
                string Series电流 = "";
                if (dtDatas.Rows.Count > 0)
                {
                    for (int i = 0; i < dtDatas.Rows.Count; i++)
                    {
                        categories += dtDatas.Rows[i]["sTime"].ToString() + "|";
                        double d电压 = dtDatas.Rows[i]["电压"] == DBNull.Value ? 0 : Convert.ToDouble(dtDatas.Rows[i]["电压"]);
                        double d电流 = dtDatas.Rows[i]["电流"] == DBNull.Value ? 0 : Convert.ToDouble(dtDatas.Rows[i]["电流"]);

                        if (d电压 != 0) d电压 = d电压 / 1000;
                        if (d电流 != 0) d电流 = d电流 / 1000;
                        Series电压 += string.Format("{0}|", d电压.ToString());
                        Series电流 += string.Format("{0}|", d电流.ToString());
                    }

                }
                object sMax1 = dtDatas.Compute("max(电流)", "");
                object sMax2 = dtDatas.Compute("max(电压)", "");
                if (sMax1.ToString() == "") sMax1 = "0";
                if (sMax2.ToString() == "") sMax2 = "0";
                if (Convert.ToDouble(sMax2) > Convert.ToDouble(sMax1))
                {
                    sMax1 = sMax2;
                }
                string sChart = string.Format(@"<chart compactDataMode='1' dataSeparator='|' caption='{0}' subcaption='{1}' axis='linear' numberPrefix='' formatNumberScale='0' decimals='3' yAxisMaxValue ='{2}'
                                        allowPinMode='0' enableIconMouseCursors='0' dynamicAxis='1' palette='3'>", "电压-电流曲线图", sCh + "-" + sRq, sMax1.ToString() == "" ? 0 : Math.Round(Convert.ToDouble(sMax1.ToString()) / 1000, 3) * 1.2);

                sReturn = string.Format(@"{0}<categories>{1}</categories><dataset seriesName='电压' anchorBgColor ='FF0080' color='FF0080'>{2}</dataset><dataset seriesName='电流' anchorBgColor ='008040' color='008040'>{3}</dataset></chart>", sChart, categories, Series电压, Series电流);
            }
            return sReturn;
        }
    }
}
